<?php

namespace app\api\controller;

use app\api\validation\Activity;
use app\payment\PayFactory;
use app\services\ActivityService;
use app\services\PaymentService;
use app\services\WorshipService;
use support\Db;
use support\Request;

class ActivityController
{
    public function list(Request $request)
    {
        try {
            $id = $request->post('id');
            $page = $request->post('page', 1);
            $name = $request->post('name', '');
            $length = $request->post('length', 10);
            $isRecommend = $request->post('is_recommend');

            $list = ActivityService::list($page, $length, $id, $name, $isRecommend);

            return ok_rsp('成功', $list);
        } catch (\Exception $e) {
            return err_rsp($e->getMessage());
        }
    }

    public function categories(Request $request)
    {
        try {
            $list = ActivityService::categories();

            return ok_rsp('成功', $list);
        } catch (\Exception $e) {
            return err_rsp($e->getMessage());
        }
    }

    public function detail(Request $request)
    {
        try {
            $id = $request->post('id');

            if (empty($id)) {
                throw new \Exception('ID不能为空');
            }

            $data = ActivityService::detail($id);

            return ok_rsp('成功', $data);
        } catch (\Exception $e) {
            return err_rsp($e->getMessage());
        }
    }

    public function collect(Request $request)
    {
        try {
            $id = $request->post('id');

            if (empty($id)) {
                throw new \Exception('ID不能为空');
            }

            ActivityService::collect($id);

            return ok_rsp('成功');
        } catch (\Exception $e) {
            return err_rsp($e->getMessage());
        }
    }

    public function uncollect(Request $request)
    {
        try {
            $id = $request->post('id');

            if (empty($id)) {
                throw new \Exception('ID不能为空');
            }

            ActivityService::uncollect($id);

            return ok_rsp('成功');
        } catch (\Exception $e) {
            return err_rsp($e->getMessage());
        }
    }


    public function share(Request $request)
    {
        try {
            $id = $request->post('id');

            if (empty($id)) {
                throw new \Exception('ID不能为空');
            }

            ActivityService::share($id);

            return ok_rsp('成功');
        } catch (\Exception $e) {
            return err_rsp($e->getMessage());
        }
    }

}